package com.wechatapp.mengyao.poetry.controller;

import com.wechatapp.mengyao.poetry.core.JsonFieldFilterDef;
import com.wechatapp.mengyao.poetry.core.PageResult;
import com.wechatapp.mengyao.poetry.core.RestResponse;
import com.wechatapp.mengyao.poetry.vo.ChinesePoetryPageView;
import com.wechatapp.mengyao.poetry.entity.PoetryType;
import com.wechatapp.mengyao.poetry.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yanghuaxu
 * @date 2025/5/21 11:01
 */
@RestController
@RequestMapping("/api/v1/favorite")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @PostMapping("/{poetryId}")
    public RestResponse<Void> addFavorite(@PathVariable Integer poetryId) {
        favoriteService.addFavorite(poetryId);
        return RestResponse.ok(null);
    }

    @DeleteMapping("/{poetryId}")
    public RestResponse<Void> cancelFavorite(@PathVariable Integer poetryId) {
        favoriteService.cancelFavorite(poetryId);
        return RestResponse.ok(null);
    }

    @GetMapping("/page")
    @JsonFieldFilterDef({
            @JsonFieldFilterDef.Entry(type = ChinesePoetryPageView.class, exclude = {"contentString"})
    })
    public RestResponse<PageResult<ChinesePoetryPageView>> getFavoriteList(@RequestParam Map<String, String> map) {

        return RestResponse.ok(favoriteService.getFavoriteList(map));
    }

    @GetMapping("/type")
    public RestResponse<List<PoetryType>> getCurrentUserFavoriteTypeList() {

        return RestResponse.ok(favoriteService.getCurrentUserFavoriteTypeList());
    }

}
